// cookie
// ' name=value;expires=日期;path=xx;domain=xx;secure '
//设置,修改,删除,
// 设置值得时候,已经进行了编码,那么将来出来的时候,也要 进行转码
function setCookie(name, value, num, path, domain, secure) {
    var strCookie = "";
    if (name) {
        // aaa=bbb
        strCookie += encodeURIComponent(name) + "=" + encodeURIComponent(value) + ";"
    }
    if (typeof (num) == 'number') {
        var date = new Date();
        date.setDate(date.getDate() + num);
        strCookie += "expires=" + date.toUTCString() + ";"
    }

    if (path) {
        strCookie += "path=" + path + ";"
    }

    if (domain) {
        strCookie += "domain=" + domain + ";"
    }

    if (secure) {
        strCookie += "secure"
    }

    return document.cookie = strCookie
}

//cookie的获取 根据键得到值

function getCookieAll() {

    var obj = {};
    // 出来要进行 解码
    var cookieStr = decodeURIComponent(document.cookie);
    // 1  aaa=123
    // 2  aaa=123;bbb=123

    var arr = cookieStr.split(";"); //1. [aaa=123]  //2. ["aaa=123"," bbb=123"]
    for (var i = 0; i < arr.length; i++) {
        var tmpArr = arr[i].split("="); // 1. aaa=123   2.1  aaa=123  2.2 " bbb=123"
        // tmpArr   1.[aaa,123]  2.1 [ aaa,123] 2.2 [ bbb,123]

        obj[tmpArr[0].trim()] = tmpArr[1];

    }
    return obj;
}

function getCookieByName(name) {
    var obj = getCookieAll(); // {aaa:123,bbb:123}
    return obj[name]

}

//删除

function removeCookie(name) {

    var date = new Date();
    date.setDate(date.getDate() - 1);
    // name aaa     aaa=" "
    document.coockie = name + "=" + " ;" + "expires=" + date.toUTCString();

}